<?php


// [begin] Warnings Mod 1.0.7 
//require('./common.php');
$current_time = time();
if ( $current_time > ($bb_cfg['warnings_time'] + 300) )
{
	$sql = "SELECT * FROM " . BB_WARNINGS . " WHERE warning_proceed = 0 AND warning_expires < $current_time AND warning_expires != " . WARNING_INFINITY . " LIMIT 1 ";
	$result = DB()->sql_query($sql) or message_die(GENERAL_MESSAGE, 'Error getting actions topics', '', __LINE__, __FILE__, $sql);

	$users_warning = $users_ban = $warnings_type_warning = $warnings_type_ban = array();

	if (DB()->num_rows($result))
	{
		while ($row = DB()->sql_fetchrow($result))
		{
			switch ($row['warning_type'])
			{
				case WARNING_TYPE_WARNING:
					if ( !in_array($row['warning_user_id'], $users_warning) )
					{
						$users_warning[] = $row['warning_user_id'];
						$warnings_type_warning[] = $row['warning_id'];
					}
				break;

				case WARNING_TYPE_BAN:
					$users_ban[] = $row['warning_user_id'];
					$warnings_type_ban[] = $row['warning_id'];
				break;
			}
   		}

  		if ( count($users_warning) )
  		{
	   		$users_warning_list = implode($users_warning, ',');
	   		$warnings_type_warning_list = implode($warnings_type_warning, ','); 

			$sql = "UPDATE " . BB_USERS . " u, " . BB_WARNINGS . " w SET u.user_warnings = u.user_warnings - 1, w.warning_proceed = 1 WHERE u.user_id IN($users_warning_list) AND w.warning_id IN($warnings_type_warning_list)";
			DB()->sql_query($sql) or message_die(GENERAL_MESSAGE, 'Error updating user warnings', '', __LINE__, __FILE__, $sql);
		}
		
  		if ( count($users_ban) )
  		{
	   		$users_ban_list = implode($users_ban, ',');
	   		$warnings_type_ban_list = implode($warnings_type_ban, ','); 

			$sql = "UPDATE " . BB_USERS . " u, " . BB_WARNINGS . " w SET u.user_banned = 0, w.warning_proceed = 1 WHERE u.user_id IN($users_ban_list) AND w.warning_id IN($warnings_type_ban_list)";
			DB()->sql_query($sql) or message_die(GENERAL_MESSAGE, 'Error updating user warnings', '', __LINE__, __FILE__, $sql);
		}
	}

	$sql = "UPDATE " . BB_CONFIG . " SET config_value ='$current_time' WHERE config_name = 'warnings_time'";
	DB()->sql_query($sql) or message_die(GENERAL_MESSAGE, 'Error updating warnings time', '', __LINE__, __FILE__, $sql);
}
// [end] Warnings Mod 1.0.7



?>